package controller;
import java.util.List;



import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration;
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Import;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.test.util.JsonResult;

import entity.SysFunc;
import service.SysFuncService;
/**
 * Created by wenchao.ren on 2014/4/26.
 */
@SpringBootApplication
//启注解事务管理  
@Controller
@Import (SysFuncService.class)

public class SysFuncController {

	@Autowired
	private SysFuncService sysFuncService;

	@RequestMapping(value = "sysFuncList", method = RequestMethod.GET)
    public String SysFuncList(Model model) {
    	//ModelAndView view = new ModelAndView("/sys/SysFuncList");
    	List<SysFunc> sysFuncList = sysFuncService.find();
    	//view.addObject("SysFuncList", SysFuncList);
    	model.addAttribute("sysFuncList", sysFuncList);
        return "sys/sysFuncList";
    }
	
	
	@ResponseBody
	@RequestMapping(value = "sysFunc_list.json")
	public List<SysFunc> listSysFunc() {
		List<SysFunc> userList = sysFuncService.find();
		return userList;
	}
	
	@RequestMapping(value = "sysFuncEdit", method = RequestMethod.GET)
    public String userEdit(Long  seqid,Model model) {
    	SysFunc sysFunc = new SysFunc();
    	if(seqid!=null){
    		sysFunc = sysFuncService.findById(seqid);
    	}
    	model.addAttribute("sysFunc", sysFunc);
    	 return "sys/sysFuncEdit";
    }
	
	/**
	 * 保存用户修改信息
	 * 
	 * @param tblStage
	 * @return
	 */
	@RequestMapping(value = "sysFunc_save.json")
	@ResponseBody
	public JsonResult saveUser(SysFunc sysFunc) {
		JsonResult result = JsonResult.newInstance();
		sysFuncService.save(sysFunc);
		return result;
	}

	/**
	 * 批量删除用户
	 * 
	 * @param ids
	 * @return
	 */
	@RequestMapping(value = "sysFunc_del.json")
	@ResponseBody
	public JsonResult delUsers(String ids) {
		JsonResult result = JsonResult.newInstance();
		sysFuncService.deleteByIds(ids.split(","));
		return result;
	}
	
	
    
}
